package com.uestc.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;

/**
 * 使用JAVA 8的时间工具包
 * 
 * @author justyoung
 *
 */
public class TimeUtil8 {
	public static String getNow() {
		LocalDateTime today = LocalDateTime.now();
		return today.toString();
	}
	
	public static String getToday() {
		LocalDate today = LocalDate.now();
		return today.toString();
	}

	public static int compareTime(String time1, String time2) {
		LocalDateTime t = LocalDateTime.parse(time1);
		LocalDateTime t2 = LocalDateTime.parse(time2);
		return t.compareTo(t2);
	}

	/**
	 * 返回两个日期间的日期，包括自身的两天
	 * 
	 * @param time1
	 *            开始时间
	 * @param time2
	 *            结束时间
	 * @return
	 */
	public static ArrayList<String> getDatesBetweenTowDates(String time1, String time2) {
		LocalDate t1 = LocalDate.parse(time1);
		LocalDate t2 = LocalDate.parse(time2);
		ArrayList<String> list = new ArrayList<>();
		while (t1.compareTo(t2) < 0) {
			list.add(t1.toString());
			t1 = t1.plusDays(1);
		}
		list.add(t2.toString());
		return list;
	}

	/**
	 * 计算两个时间的差值, 判断差值是否在minutes以外
	 * 
	 * @param time1
	 * @param time2
	 * @param minutes
	 * @return
	 */
	public static int isDistanceInMinutes(long minutes, String time1, String time2) {
		LocalDateTime t = LocalDateTime.parse(time1);
		LocalDateTime t2 = LocalDateTime.parse(time2);
		LocalDateTime time = t2.plusMinutes(minutes);
		return t.compareTo(time);
	}

	public static void main(String[] args) {
		String string = "adfadfa";
		String[] strings = string.split(";");
		System.out.println(strings[0]);
	}
}
